package com.letoken.platform.app.configuration;

import com.letoken.platform.repo.mq.constant.ImUserConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wyl
 * @date 2023/2/20 12:09
 * @Version 1.0
 */
@Configuration
public class RabbitImUserLoginConfig {
    // ===========================
    // 交换机

    /**
     * 普通交换机-执行及时任务
     * @return
     */
    @Bean
    TopicExchange imUserTopicExchange() {
        return new TopicExchange(ImUserConstant.TOPIC_EXCHANGE_IM_USER_LOGIN, true, false);
    }

    @Bean
    public Queue queueImUserLogin() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange",ImUserConstant.TOPIC_EXCHANGE_IM_USER_LOGIN);
        args.put("x-dead-letter-routing-key",ImUserConstant.QUEUE_IM_USER_LOGIN);
        return new Queue(ImUserConstant.QUEUE_IM_USER_LOGIN,true, false, false, args);
    }
    @Bean
    Binding bindingImUserLogin() {
        return BindingBuilder.bind(this.queueImUserLogin()).to(this.imUserTopicExchange()).with(ImUserConstant.QUEUE_IM_USER_LOGIN);
    }
}
